#include "WVWMatch.h"


namespace Gw2API{

#define GW2_TIME_STR "%d-%d-%dT%d:%d:%dZ"

	time_t parseTimeString(std::string*);

	WVWMatch::WVWMatch(std::string *match_id, int red_id, int blue_id, int green_id, std::string *start, std::string *end)
	{
		match_id == 0 ? this->match_id = "" : this->match_id = *match_id;
		this->red_id = red_id;
		this->blue_id = blue_id;
		this->green_id = green_id;
		if(start != 0)
			this->start = parseTimeString(start);
		if(end != 0)
			this->end = parseTimeString(end);
	}


	WVWMatch::~WVWMatch(void)
	{
	}


	time_t parseTimeString(std::string *ptr){
		time_t currentTime;
		time(&currentTime);
		struct tm buffer;
		localtime_s(&buffer, &currentTime);
		sscanf_s(ptr->c_str(), GW2_TIME_STR, &buffer.tm_year, &buffer.tm_mon, &buffer.tm_mday, &buffer.tm_hour,
			&buffer.tm_min, &buffer.tm_sec, sizeof(struct tm));
		buffer.tm_year -= 1900;
		buffer.tm_mon--;
		return mktime(&buffer);
	}
};